/*
 *  Project     : QKeyboardStatistic
 *  Author      : Durachenko Aleksey V. <durachenko.aleksey@gmail.com>, 2011
 *  Licence     : GNU GENERAL PUBLIC LICENSE Version 2
 */
#ifndef CSTATISTIC_H
#define CSTATISTIC_H

#include <QObject>
#include <QDateTime>
#include "cdatabase.h"
#include "global.h"

class CStatistic : public QObject
{
Q_OBJECT
public:
    CStatistic(CDatabase* dataBase, int autoSavePeriod, QObject* parent);
    ~CStatistic();

    inline qint64 keyTotal() const
    {
        return mKeyTotal;
    }

    inline qint64 keyMonth() const
    {
        return mKeyMonth;
    }

    inline qint64 keyWeek() const
    {
        return mKeyWeek;
    }

    inline qint64 keyDay() const
    {
        return mKeyDay;
    }

    inline qint64 keyHour() const
    {
        return mKeyHour;
    }

    inline qint64 mousePressTotal() const
    {
        return mMousePressTotal;
    }

    inline qint64 mousePressMonth() const
    {
        return mMousePressMonth;
    }

    inline qint64 mousePressWeek() const
    {
        return mMousePressWeek;
    }

    inline qint64 mousePressDay() const
    {
        return mMousePressDay;
    }

    inline qint64 mousePressHour() const
    {
        return mMousePressHour;
    }

    inline qint64 mileageTotal() const
    {
        return mMileageTotal;
    }

    inline qint64 mileageMonth() const
    {
        return mMileageMonth;
    }

    inline qint64 mileageWeek() const
    {
        return mMileageWeek;
    }

    inline qint64 mileageDay() const
    {
        return mMileageDay;
    }

    inline qint64 mileageHour() const
    {
        return mMileageHour;
    }

protected:
    void timerEvent(QTimerEvent* event);

signals:
    void keyStatisticChanged();
    void mousePressStatisticChanged();
    void mileageStatisticChanged();

public slots:
    void incKeyCount();
    void incMousePressCount();
    void incMileage(qint64 mileage);

private:
    void clearLast();

    int mMinuteTimer;
    int mSaveTimer;
    int mAutoSavePeriod;
    CDatabase* mDatabase;

    qint64 mKeyTotal;
    qint64 mKeyMonth;
    qint64 mKeyWeek;
    qint64 mKeyDay;
    qint64 mKeyHour;
    qint64 mKeyLast;

    qint64 mMousePressTotal;
    qint64 mMousePressMonth;
    qint64 mMousePressWeek;
    qint64 mMousePressDay;
    qint64 mMousePressHour;
    qint64 mMousePressLast;

    qint64 mMileageTotal;
    qint64 mMileageMonth;
    qint64 mMileageWeek;
    qint64 mMileageDay;
    qint64 mMileageHour;
    qint64 mMileageLast;

    QDateTime mLastHour;
    QDateTime mLastDay;
    QDateTime mLastWeek;
    QDateTime mLastMonth;

};

#endif
